<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopRefundTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_refund', ['comment' => '退款', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('refund_sn', 'string', ['limit' =>  60, 'default' => '', 'comment' => '退款单号'])
            ->addColumn('order_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '订单'])
            ->addColumn('pay_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '支付'])
            ->addColumn(Column::enum('pay_type', ['wechat', 'alipay', 'money', 'score'])->setNull(true)->setDefault(null)->setComment('支付方式:wechat=微信支付,alipay=支付宝,money=钱包支付,score=积分支付'))
            ->addColumn('refund_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '退款金额'])
            ->addColumn('refund_type', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '退款类型'])
            ->addColumn('refund_method', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '退款方式'])
            ->addColumn(Column::enum('status', ['ing', 'completed', 'fail'])->setNull(true)->setDefault('ing')->setComment('退款状态:ing=退款中,completed=退款完成,fail=退款失败'))
            ->addColumn('remark', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '备注'])
            ->addColumn('platform', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '下单平台'])
            ->addColumn('payment_json', 'string', ['limit' => 2048, 'null' => true, 'default' => null, 'comment' => '交易原始数据'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('order_id')
            ->addIndex('refund_sn', ['unique'  =>  true])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_refund');
        $table->drop();
    }
}
